import { DirectiveDefinitionNode } from 'graphql';
import {
  AUTHENTICATED,
  BOOLEAN_SCALAR,
  COMPOSE_DIRECTIVE,
  CONFIGURE_CHILD_DESCRIPTIONS,
  CONFIGURE_DESCRIPTION,
  CONNECT_FIELD_RESOLVER,
  DEPRECATED,
  EDFS_KAFKA_PUBLISH,
  EDFS_KAFKA_SUBSCRIBE,
  EDFS_NATS_PUBLISH,
  EDFS_NATS_REQUEST,
  EDFS_NATS_SUBSCRIBE,
  EDFS_REDIS_PUBLISH,
  EDFS_REDIS_SUBSCRIBE,
  EXTENDS,
  EXTERNAL,
  FIELD_SET_SCALAR,
  FLOAT_SCALAR,
  ID_SCALAR,
  INACCESSIBLE,
  INT_SCALAR,
  INTERFACE_OBJECT,
  KEY,
  LINK,
  ONE_OF,
  OVERRIDE,
  PROVIDES,
  REQUIRE_FETCH_REASONS,
  REQUIRES,
  REQUIRES_SCOPES,
  SCOPE_SCALAR,
  SEMANTIC_NON_NULL,
  SHAREABLE,
  SPECIFIED_BY,
  STRING_SCALAR,
  SUBSCRIPTION_FILTER,
  TAG,
} from '../../utils/string-constants';
import { DirectiveName } from '../../types/types';
import {
  AUTHENTICATED_DEFINITION,
  COMPOSE_DIRECTIVE_DEFINITION,
  CONFIGURE_CHILD_DESCRIPTIONS_DEFINITION,
  CONFIGURE_DESCRIPTION_DEFINITION,
  CONNECT_FIELD_RESOLVER_DEFINITION,
  DEPRECATED_DEFINITION,
  EDFS_KAFKA_PUBLISH_DEFINITION,
  EDFS_KAFKA_SUBSCRIBE_DEFINITION,
  EDFS_NATS_PUBLISH_DEFINITION,
  EDFS_NATS_REQUEST_DEFINITION,
  EDFS_NATS_SUBSCRIBE_DEFINITION,
  EDFS_REDIS_PUBLISH_DEFINITION,
  EDFS_REDIS_SUBSCRIBE_DEFINITION,
  EXTENDS_DEFINITION,
  EXTERNAL_DEFINITION,
  INACCESSIBLE_DEFINITION,
  INTERFACE_OBJECT_DEFINITION,
  KEY_DEFINITION,
  LINK_DEFINITION,
  ONE_OF_DEFINITION,
  OVERRIDE_DEFINITION,
  PROVIDES_DEFINITION,
  REQUIRE_FETCH_REASONS_DEFINITION,
  REQUIRES_DEFINITION,
  REQUIRES_SCOPES_DEFINITION,
  SEMANTIC_NON_NULL_DEFINITION,
  SHAREABLE_DEFINITION,
  SPECIFIED_BY_DEFINITION,
  SUBSCRIPTION_FILTER_DEFINITION,
  TAG_DEFINITION,
} from './directive-definitions';

export const DIRECTIVE_DEFINITION_BY_NAME: ReadonlyMap<DirectiveName, DirectiveDefinitionNode> = new Map<
  DirectiveName,
  DirectiveDefinitionNode
>([
  [AUTHENTICATED, AUTHENTICATED_DEFINITION],
  [COMPOSE_DIRECTIVE, COMPOSE_DIRECTIVE_DEFINITION],
  [CONFIGURE_DESCRIPTION, CONFIGURE_DESCRIPTION_DEFINITION],
  [CONFIGURE_CHILD_DESCRIPTIONS, CONFIGURE_CHILD_DESCRIPTIONS_DEFINITION],
  [CONNECT_FIELD_RESOLVER, CONNECT_FIELD_RESOLVER_DEFINITION],
  [DEPRECATED, DEPRECATED_DEFINITION],
  [EDFS_KAFKA_PUBLISH, EDFS_KAFKA_PUBLISH_DEFINITION],
  [EDFS_KAFKA_SUBSCRIBE, EDFS_KAFKA_SUBSCRIBE_DEFINITION],
  [EDFS_NATS_PUBLISH, EDFS_NATS_PUBLISH_DEFINITION],
  [EDFS_NATS_REQUEST, EDFS_NATS_REQUEST_DEFINITION],
  [EDFS_NATS_SUBSCRIBE, EDFS_NATS_SUBSCRIBE_DEFINITION],
  [EDFS_REDIS_PUBLISH, EDFS_REDIS_PUBLISH_DEFINITION],
  [EDFS_REDIS_SUBSCRIBE, EDFS_REDIS_SUBSCRIBE_DEFINITION],
  [EXTENDS, EXTENDS_DEFINITION],
  [EXTERNAL, EXTERNAL_DEFINITION],
  [INACCESSIBLE, INACCESSIBLE_DEFINITION],
  [INTERFACE_OBJECT, INTERFACE_OBJECT_DEFINITION],
  [KEY, KEY_DEFINITION],
  [LINK, LINK_DEFINITION],
  [ONE_OF, ONE_OF_DEFINITION],
  [OVERRIDE, OVERRIDE_DEFINITION],
  [PROVIDES, PROVIDES_DEFINITION],
  [REQUIRE_FETCH_REASONS, REQUIRE_FETCH_REASONS_DEFINITION],
  [REQUIRES, REQUIRES_DEFINITION],
  [REQUIRES_SCOPES, REQUIRES_SCOPES_DEFINITION],
  [SEMANTIC_NON_NULL, SEMANTIC_NON_NULL_DEFINITION],
  [SHAREABLE, SHAREABLE_DEFINITION],
  [SPECIFIED_BY, SPECIFIED_BY_DEFINITION],
  [SUBSCRIPTION_FILTER, SUBSCRIPTION_FILTER_DEFINITION],
  [TAG, TAG_DEFINITION],
]);

export const BASE_SCALARS: ReadonlySet<string> = new Set<string>([
  '_Any',
  '_Entities',
  BOOLEAN_SCALAR,
  FLOAT_SCALAR,
  ID_SCALAR,
  INT_SCALAR,
  FIELD_SET_SCALAR,
  SCOPE_SCALAR,
  STRING_SCALAR,
]);

export const V2_DIRECTIVE_DEFINITION_BY_DIRECTIVE_NAME = new Map<DirectiveName, DirectiveDefinitionNode>([
  [AUTHENTICATED, AUTHENTICATED_DEFINITION],
  [COMPOSE_DIRECTIVE, COMPOSE_DIRECTIVE_DEFINITION],
  [INACCESSIBLE, INACCESSIBLE_DEFINITION],
  [INTERFACE_OBJECT, INTERFACE_OBJECT_DEFINITION],
  [LINK, LINK_DEFINITION],
  [OVERRIDE, OVERRIDE_DEFINITION],
  [REQUIRES_SCOPES, REQUIRES_SCOPES_DEFINITION],
  [SHAREABLE, SHAREABLE_DEFINITION],
]);

export const EDFS_ARGS_REGEXP = /{{\s*args\.([a-zA-Z0-9_]+)\s*}}/g;

export const MAX_OR_SCOPES = 16;
